﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		FeedController.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 // 
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion

using System.Text;
using System.Web.Mvc;
using Dexter.Core;
using Dexter.Logger.Contracts;
using Dexter.Search;
using Dexter.Services;
using Dexter.Web.Mvc.Filters;
using Dexter.Web.Mvc.Results;
using Dexter.Web.Syndication.Contracts;
using Dexter.Web.Utils;

namespace Dexter.Web.Mvc.Controllers.FrontEnd {
	[DexterCallFilter ( true )]
	public class FeedController : PublicControllerBase {
		readonly IRssService rssService;

		public FeedController ( ISearchService searchService , ICommentService commentService , IReferrerService referrerService , IConfigurationService configurationService , IWebUtils webUtils , ILogger logger , IUrlBuilder urlBuilder , IBlogRollService blogRollService , ICategoryService categoryService , IPostService postService , IThemeManager themeManager , ITagService tagService , IPageService pageService , IRssService rssService ) : base ( searchService , commentService , referrerService , configurationService , webUtils , logger , urlBuilder , blogRollService , categoryService , postService , themeManager , tagService , pageService ) {
			this.rssService = rssService;
		}

		[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Head)]
		public ActionResult Rss ( ) {
			var posts = PostService.GetPublished ( 0 , base.Configuration.ElementInListsConfiguration.NumberOfElementsInFeed );

			return new RssResult ( base.Configuration , posts.Result , this.rssService , base.UrlBuilder );
		}

		[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Head)]
		public ActionResult Rsd() {
			var sb = new StringBuilder ( );
			sb.Append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" );
			sb.Append ( "<rsd version=\"1.0\" xmlns=\"http://archipelago.phrasewise.com/rsd\"> " );
			sb.Append ( "<service>" );
			sb.Append ( "<engineName>Dexter Blog Engine</engineName>" );
			sb.AppendFormat ( "<engineLink>{0}</engineLink> ", DexterInfo.Website );
			sb.AppendFormat ( "<homePageLink>{0}</homePageLink> ", base.UrlBuilder.HomePage );
			sb.Append ( "<apis>" );
			sb.AppendFormat ( "<api name=\"WordPress\" blogID=\"1\" preferred=\"false\" apiLink=\"{0}\" />", base.UrlBuilder.MetaWeblogApi );
			sb.AppendFormat ( "<api name=\"Movable Type\" blogID=\"1\" preferred=\"false\" apiLink=\"{0}\" />", base.UrlBuilder.MetaWeblogApi );
			sb.AppendFormat ( "<api name=\"MetaWeblog\" blogID=\"1\" preferred=\"true\" apiLink=\"{0}\" />", base.UrlBuilder.MetaWeblogApi );
			sb.AppendFormat ( "<api name=\"Blogger\" blogID=\"1\" preferred=\"false\" apiLink=\"{0}\" />", base.UrlBuilder.MetaWeblogApi );
			sb.Append ( "</apis>" );
			sb.Append ( "</service>" );
			sb.Append ( "</rsd> " );

			return Content ( sb.ToString ( ) , "text/xml" );
		}
	}
}
